//
//  InterstitialVC.m
//  CJModileAdDemo
//
//  Created by CJ on 2022/3/7.
//

#import "InterstitialVC.h"
#import <CJMobileAd/CJMobileAd.h>
#import <WindMillSDK/WindMillIntersititialAd.h>
#import <WindMillSDK/WindMillAdRequest.h>
#import <WindMillSDK/WindMillConstant.h>

@interface InterstitialVC ()<WindMillIntersititialAdDelegate>

@property (nonatomic, strong) WindMillIntersititialAd *intersititialAd;

@end

@implementation InterstitialVC

@synthesize customView = _customView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)loadAdData {
    WindMillAdRequest *request = [WindMillAdRequest request];
    request.userId = @"user_id";
    request.placementId = @"2117494159674178";
    if (self.intersititialAd == nil) {
        self.intersititialAd = [[WindMillIntersititialAd alloc] initWithRequest:request];
    }
    self.intersititialAd.delegate = self;
    [self.intersititialAd loadAdData];
}

- (void)setupUI {
    self.title = @"InterstitialAd";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        NSLog(@"事件:%s", __FUNCTION__);
        [self loadAdData];
        return;
    }
    [self.intersititialAd showAdFromRootViewController:self options:nil];
}


- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak InterstitialVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

#pragma mark BUNativeExpressFullscreenVideoAdDelegate
- (void)intersititialAdDidLoad:(WindMillIntersititialAd *)intersititialAd {
    [self.customView canShowStatus:true errorMsg:@""];
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)intersititialAdDidLoad:(WindMillIntersititialAd *)intersititialAd didFailWithError:(NSError *)error {
    [self.customView canShowStatus:false errorMsg:error.debugDescription];
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)intersititialAdDidVisible:(WindMillIntersititialAd *)intersititialAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)intersititialAdDidClick:(WindMillIntersititialAd *)intersititialAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)intersititialAdDidClose:(WindMillIntersititialAd *)intersititialAd {
    [self.customView canShowStatus:false errorMsg:@""];
    NSLog(@"事件:%s", __FUNCTION__);
}
@end
